{% load static %}
<script type="application/javascript" src="{% static "chosen-js/chosen.jquery.min.js" %}"></script>
<script type="application/javascript">
    $(function () {
        $(function () {

        })

        $(function () {
            $('.similar-filters select[multiple]').not('[data-tagulous]').each(function () {
                // Removing bootstrap-select class and replacing with select2 to avoid library conflicts
                // leading to visually unappealing dropdowns
                $(this).removeClass('selectpicker').closest('.bootstrap-select').replaceWith($(this));
                $(this).select2(
                )
            })
            $('input[data-tagulous]').each(function () {
                Tagulous.select2($(this))
            })
        })


        $('.toggle-filters').on('click', function () {
            $(this).toggleClass("dropup");
        })

        <!-- what works on every other page with the 'e' keydown, conflicts here with the input fields in the filter div, stoppropagation 'fixes' this -->
        $('.is-filters').keydown( function(e) {
            e.stopPropagation();
        })

        $('#clear_js').on('click', function() {
            clear_form($(this).closest('form'))
        })
    })

    {% if title_words %}
        var title_words = [
                {% for word in title_words %}
                    "{{word|escapejs}}",
                {% endfor %}
            ];
            {% comment %}ideally we use the form.prefix but then we have the trailing dash... django templates are hard{% endcomment %}
            $("#id_title, #id_finding-title").autocomplete({
                source: title_words
            });
    {% endif %}

    {% if component_words %}
            var component_words = [
                {% for word in component_words %}
                    "{{word|escapejs}}",
                {% endfor %}
            ];

            $("#id_component_name, #id_finding-component_name").autocomplete({
                source: component_words
            });
    {% endif %}
</script>